﻿&"D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars32.bat"

$SolutionDir = "D:\Work\Bridge6"

# 设置UTF-8编码，确保中文正常显示
$OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8

Write-Host ""7. 构建analysis/Release库...""
Set-Location -Path "$SolutionDir\analysis"
New-Item -Path "build\win32_release" -ItemType Directory -Force | Out-Null
Set-Location -Path "build\win32_release"
cmake ..\.. -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DARCH=Win32 
ninja -v -j8
ninja install

Write-Host ""8. 构建analysis/Debug库...""
Set-Location -Path "$SolutionDir\analysis"
New-Item -Path "build\win32_debug" -ItemType Directory -Force | Out-Null
Set-Location -Path "build\win32_debug"
cmake ..\.. -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -DARCH=Win32
ninja -v -j8
ninja install

Write-Host ""9. 构建BridgeAnalysis/Release库...""
Set-Location -Path "$SolutionDir\BridgeAnalysis"
New-Item -Path "build\win32_release" -ItemType Directory -Force | Out-Null
Set-Location -Path "build\win32_release"
cmake ..\.. -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DARCH=Win32 
ninja -v -j8
ninja install

Write-Host ""10. 构建BridgeAnalysis/Debug库...""
Set-Location -Path "$SolutionDir\BridgeAnalysis"
New-Item -Path "build\win32_debug" -ItemType Directory -Force | Out-Null
Set-Location -Path "build\win32_debug"
cmake ..\.. -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -DARCH=Win32
ninja -v -j8
ninja install

Write-Host ""11. 构建ChemDLL/Release库...""
Set-Location -Path "$SolutionDir\ChemDLL"
New-Item -Path "build\win32_release" -ItemType Directory -Force | Out-Null
Set-Location -Path "build\win32_release"
cmake ..\.. -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DARCH=Win32 
ninja -v -j8
ninja install

Write-Host ""12. 构建ChemDLL/Debug库...""
Set-Location -Path "$SolutionDir\ChemDLL"
New-Item -Path "build\win32_debug" -ItemType Directory -Force | Out-Null
Set-Location -Path "build\win32_debug"
cmake ..\.. -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -DARCH=Win32
ninja -v -j8
ninja install

Write-Host ""13. 构建BridgeTest/Release执行程序...""
Set-Location -Path "$SolutionDir\BridgeTest"
New-Item -Path "build\win32_release" -ItemType Directory -Force | Out-Null
Set-Location -Path "build\win32_release"
cmake ..\.. -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DARCH=Win32 
ninja -v -j8
ninja install

Write-Host ""14. 构建BridgeTest/Debug执行程序...""
Set-Location -Path "$SolutionDir\BridgeTest"
New-Item -Path "build\win32_debug" -ItemType Directory -Force | Out-Null
Set-Location -Path "build\win32_debug"
cmake ..\.. -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -DARCH=Win32
ninja -v -j8
ninja install

Write-Host ""15. 构建LogService/Release执行程序...""
Set-Location -Path "$SolutionDir\LogService"
New-Item -Path "build\win32_release" -ItemType Directory -Force | Out-Null
Set-Location -Path "build\win32_release"
cmake ..\.. -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DARCH=Win32 
ninja -v -j8
ninja install

Write-Host ""16. 构建LogService/Debug执行程序...""
Set-Location -Path "$SolutionDir\LogService"
New-Item -Path "build\win32_debug" -ItemType Directory -Force | Out-Null
Set-Location -Path "build\win32_debug"
cmake ..\.. -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -DARCH=Win32
ninja -v -j8
ninja install

Write-Host ""17. 测试BridgeTest/Release执行程序...""
Set-Location -Path "$SolutionDir\Win32\Release"
.\BridgeTest.exe --gtest_filter=AnalysisTest2*
.\BridgeTest.exe --gtest_filter=ChemDLLTest1*

Write-Host ""18. 测试BridgeTest/Debug执行程序...""
Set-Location -Path "$SolutionDir\Win32\Debug"
.\BridgeTest.exe --gtest_filter=AnalysisTest2*
.\BridgeTest.exe --gtest_filter=ChemDLLTest1*